# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=xavs
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.55
pkgrel=2
pkgdesc="XAVS is to implement high quality encoder and decoder of the Audio Video Standard of China (AVS). (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://xavs.sourceforge.io/"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "${MINGW_PACKAGE_PREFIX}-yasm")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
source=("https://github.com/OpenMandrivaAssociation/xavs/raw/master/xavs-${pkgver}.tar.xz"
        "0001-xavs-0.1.55-fix-dynamic-build.patch"
        "0002-xavs-0.1.55-fix-asm.patch")
sha256sums=('178bf04ffc5edd9acfa8188acbeeab16e24e4e43f4465729e8619f844e5901f2'
            'dd717ff5096ea2ffd4c4793461269eee089e54e7db1184669d8f00c0fc67f1a4'
            '1559e0dfb21ee6f67dbd996ae0bb0c67987706db3144199202890de37cb7d8b4')

prepare(){
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/0001-xavs-0.1.55-fix-dynamic-build.patch"
  patch -Np1 -i "${srcdir}/0002-xavs-0.1.55-fix-asm.patch"
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --disable-asm \
    --enable-shared

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
